#include <stdio.h>
#include <stdlib.h>
typedef struct tree
{
    int data;
    struct tree *left, *right;
};

void CreatTree(tree *&root, int *array, int n, int index)
{
    if (index >= n)
        return;
    if (array[index] == NULL)
    {
        root = NULL;
        return;
    }
    root = (tree *)malloc(sizeof(tree));
    root->data = array[index];
    root->left = root->right = NULL;
    CreatTree(root->left, array, n, 2 * index + 1);
    CreatTree(root->right, array, n, 2 * index + 2);
    return;
}
tree *creat()
{
    int n = 15;
    int a[15] = {1,
                 2, NULL,
                 5, 3, NULL, NULL,
                 NULL, 6, 7, 4, NULL, NULL, NULL, NULL};
    tree *root;
    CreatTree(root, a, n, 0);
    return root;
}
void midorder_traversal(tree *root)
{
    if (root)
    {
        midorder_traversal(root->left);
        printf("%3d", root->data);
        midorder_traversal(root->right);
    }
}